import pickle
import numpy as np
from sklearn import metrics
# 修改数据集
dataname = 'aps'

def smape(y_pre, y_true):
    return 1/len(y_pre) * np.sum(2 * np.abs(y_pre - y_true) / (np.abs(y_pre) + np.abs(y_true)))

with open("prediction_result_0.005_CasCN", 'rb') as f:
    data = pickle.load(f)

y_pre, y_true, loss = data

y_pre, y_true, loss = np.array(y_pre).reshape(-1, 1)[:-1], np.array(y_true).reshape(-1, 1), np.array(loss)[:-1]
print(len(y_pre), len(y_true), len(loss))
msle = metrics.mean_squared_error(y_true, y_pre)
mape = smape(y_true, y_pre)
mae = metrics.mean_absolute_error(y_true, y_pre)
r2 = metrics.r2_score(y_true, y_pre)
print(np.mean(loss))
print("Test MSLE: {}, MAPE: {},MAE:{}, R_squared: {}".format(msle, mape, mae, r2))